return g_variant_builder_end (&builder);
}
+static gboolean
+add_ref_to_set (const char *remote,
+ GFile *base,
+ GFile *child,
+ GHashTable *refs,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gboolean ret = FALSE;
+ char *contents;
+ char *relpath;
+ gsize len;
+ GString *refname;
+
+ if (!g_file_load_contents (child, cancellable, &contents, &len, NULL, error))
+ goto out;
+
+ g_strchomp (contents);
+
+ refname = g_string_new ("");
+ if (remote)
+ {
+ g_string_append (refname, remote);
+ g_string_append_c (refname, ':');
+ }
+ relpath = g_file_get_relative_path (base, child);
+ g_string_append (refname, relpath);
+ g_free (relpath);
+
+ g_hash_table_insert (refs, g_string_free (refname, FALSE), contents);
+
+ ret = TRUE;
+ out:
+ return ret;
+}
+
static gboolean
enumerate_refs_recurse (OstreeRepo *repo,
const char *remote,
}
else if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_REGULAR)
{
- char *contents;
- char *relpath;
- gsize len;
- GString *refname;
-
- if (!g_file_load_contents (child, cancellable, &contents, &len, NULL, error))
+ if (!add_ref_to_set (remote, base, child, refs,
+ cancellable, error))
goto out;
-
- g_strchomp (contents);
-
- refname = g_string_new ("");
- if (remote)
- {
- g_string_append (refname, remote);
- g_string_append_c (refname, ':');
- }
- relpath = g_file_get_relative_path (base, child);
- g_string_append (refname, relpath);
- g_free (relpath);
-
- g_hash_table_insert (refs, g_string_free (refname, FALSE), contents);
}
}
{
gs_unref_object GFile *dir = NULL;
gs_unref_object GFile *child = NULL;
+ gs_unref_object GFileInfo *info = NULL;
if (!ostree_parse_refspec (refspec_prefix, &remote, &ref_prefix, error))
goto out;
dir = g_object_ref (repo->local_heads_dir);
child = g_file_resolve_relative_path (dir, ref_prefix);
+ if (!ot_gfile_query_info_allow_noent (child, OSTREE_GIO_FAST_QUERYINFO, 0,
+ &info, cancellable, error))
+ goto out;
- if (!enumerate_refs_recurse (repo, remote, child, child,
- ret_all_refs,
+ if (info)
+ {
+ if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
+ {
+ if (!enumerate_refs_recurse (repo, remote, child, child,
+ ret_all_refs,
+ cancellable, error))
+ goto out;
+ }
+ else
+ {
+ if (!add_ref_to_set (remote, dir, child, ret_all_refs,
cancellable, error))
- goto out;
+ goto out;
+ }
+ }
}
else
{
else
{
dir = g_file_get_child (self->remote_heads_dir, remote);
-
- if (!gs_file_ensure_directory (dir, FALSE, NULL, error))
- goto out;
+
+ if (rev != NULL)
+ {
+ if (!gs_file_ensure_directory (dir, FALSE, NULL, error))
+ goto out;
+ }
}
- if (!write_checksum_file (dir, name, rev, error))
- goto out;
-
- if (self->mode == OSTREE_REPO_MODE_ARCHIVE
- || self->mode == OSTREE_REPO_MODE_ARCHIVE_Z2)
+ if (rev == NULL)
{
- if (!write_ref_summary (self, NULL, error))
+ gs_unref_object GFile *child = g_file_resolve_relative_path (dir, name);
+
+ if (g_file_query_exists (child, NULL))
+ {
+ if (!gs_file_unlink (child, NULL, error))
+ goto out;
+ }
+ }
+ else
+ {
+ if (!write_checksum_file (dir, name, rev, error))
goto out;
+
+ if (rev != NULL)
+ {
+ if (self->mode == OSTREE_REPO_MODE_ARCHIVE
+ || self->mode == OSTREE_REPO_MODE_ARCHIVE_Z2)
+ {
+ if (!write_ref_summary (self, NULL, error))
+ goto out;
+ }
+ }
}
ret = TRUE;
#include "ostree.h"
#include "ostree-repo-file.h"
+static gboolean opt_delete;
+
static GOptionEntry options[] = {
+ { "delete", 0, 0, G_OPTION_ARG_NONE, &opt_delete, "Delete refs which match PREFIX, rather than listing them", "PREFIX" },
{ NULL }
};
gs_unref_hashtable GHashTable *refs = NULL;
GHashTableIter hashiter;
gpointer hashkey, hashvalue;
- guint i;
- context = g_option_context_new ("[PREFIX...] - List refs");
+ context = g_option_context_new ("[PREFIX] - List refs");
g_option_context_add_main_entries (context, options, NULL);
if (!g_option_context_parse (context, &argc, &argv, error))
cancellable, error))
goto out;
- g_hash_table_iter_init (&hashiter, refs);
- while (g_hash_table_iter_next (&hashiter, &hashkey, &hashvalue))
+ if (!opt_delete)
+ {
+ g_hash_table_iter_init (&hashiter, refs);
+ while (g_hash_table_iter_next (&hashiter, &hashkey, &hashvalue))
+ {
+ const char *ref = hashkey;
+ g_print ("%s\n", ref);
+ }
+ }
+ else
{
- const char *ref = hashkey;
- g_print ("%s\n", ref);
+ g_hash_table_iter_init (&hashiter, refs);
+ while (g_hash_table_iter_next (&hashiter, &hashkey, &hashvalue))
+ {
+ const char *refspec = hashkey;
+ if (!ostree_repo_write_refspec (repo, refspec, NULL, error))
+ goto out;
+ }
}
ret = TRUE;